﻿<cfmodule template="../../tag/layout.cfm" bodyIsEasyUILayout="false">
<input id="id" name="id" value="<cfoutput>#rc.id#</cfoutput>" readonly="readonly" type="hidden" />
	<fieldset>
		<legend>修改组织</legend>
		<ul id="tree"></ul>
	</fieldset>
</cfmodule>
<script type="text/javascript">
	var closeDialog = function($dialog) {
		$dialog.dialog('destroy');
	}
    
    var submitForm = function($dialog, $grid, $pjq) {
		var nodes = $('#tree').tree('getChecked', [ 'checked', 'indeterminate' ]);
		var ids = [];
		for (var i = 0; i < nodes.length; i++) {
			ids.push(nodes[i].id);
		}
		
		$.post('?action=user.saveorganizationgrant', {
			id : $(':input[name="id"]').val(),
			ids : ids.join(',')
		}, function(result) {
			if (result) {
				$dialog.dialog('destroy');
			}
		}, 'json');
	};
    
	$(function() {
		parent.$.messager.progress({
			text : '数据加载中....'
		});
        
        $("#tree").tree({
            url: '?action=organization.getTree',
            method: 'get',
            checkbox : true,
			formatter : function(node) {
				return node.text;
			},onLoadSuccess : function(node, data) {
				$.post('?action=user.getOrganizationGrantTree', {
					id : $(':input[name="id"]').val()
				}, function(result) {
					if (result) {
						for (var i = 0; i < result.length; i++) {
							var node = $('#tree').tree('find', result[i].id);
							if (node) {
								var isLeaf = $('#tree').tree('isLeaf', node.target);
								if (isLeaf) {
									$('#tree').tree('check', node.target);
								}
							}
						}
					}
					parent.$.messager.progress('close');
				}, 'json');
				
			}
        });
        
		
	});

</script>